/**
 * 初始化配置信息详情对话框
 */
var ConfigurationInfoDlg = {
    validateFields: {
    	code: {
            validators: {
                notEmpty: {
                    message: '代码不能为空'
                }
            }
        },
    	description: {
            validators: {
                notEmpty: {
                    message: '描述不能为空'
                }
            }
        },
    	value: {
            validators: {
                notEmpty: {
                    message: '值不能为空'
                }
            }
        },
    	note: {
            validators: {
                notEmpty: {
                    message: '备注不能为空'
                }
            }
        },
    	productId: {
            validators: {
                notEmpty: {
                    message: '产品线不能为空'
                }
            }
        },
    	isActive: {
            validators: {
                notEmpty: {
                    message: '是否有效不能为空'
                }
            }
        },
    }
};


/**
 * 关闭此对话框
 */
ConfigurationInfoDlg.close = function() {
    parent.layer.close(parent.layer.getFrameIndex(window.name)); //先得到当前iframe层的索引,再执行关闭   
}

/**
 * 验证数据是否为空
 */
ConfigurationInfoDlg.validate = function () {
    $('#configurationInfoForm').data("bootstrapValidator").resetForm();
    $('#configurationInfoForm').bootstrapValidator('validate');
    return $("#configurationInfoForm").data('bootstrapValidator').isValid();
}

/**
 * 提交新增
 */
ConfigurationInfoDlg.addSubmit = function() {

    if (!this.validate()) {
        return;
    }
    //提交信息
    Sys.ajaxForm('configurationInfoForm',Sys.backendPath + "/cdc/configuration/add",function(res) {
        Sys.success(res.message);
    	window.parent.Configuration.table.refresh();
        ConfigurationInfoDlg.close();
    });
}

/**
 * 提交修改
 */
ConfigurationInfoDlg.editSubmit = function() {

    if (!this.validate()) {
        return;
    }
    //提交信息
    Sys.ajaxForm('configurationInfoForm',Sys.backendPath + "/cdc/configuration/update",function(res) {
        Sys.success(res.message);
    	window.parent.Configuration.table.refresh();
        ConfigurationInfoDlg.close();
    });
}

/**
 * 对值进行加密
 */
ConfigurationInfoDlg.encr = function () {
    var ajax = new $ax(Sys.backendPath + "/cdc/configuration/encr/"+$("#value").val(), function (data){
        $("#value").val(data);
    });
    ajax.start();
}

$(function() {
	Sys.initValidator("configurationInfoForm", ConfigurationInfoDlg.validateFields);
});
